<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
</body>
<script>
    /*   定义数组
    var a = new Array(1, 2, 3, 4);
       console.log(a[0]);
       console.log(a[1]);
       console.log(a[2]);
       console.log(a[3]);
       var b = [5, 6, 7, 8];
       console.log(b[0]);
       console.log(b[1]);
       console.log(b[2]);
       console.log(b[3]);
       //js中数组长度可变,类型可变
       a[8] = 10;
       a[9] = "a";
       console.log(a[5]);//undefined
       console.log(a[6]);//undefined
       console.log(a[7]);//undefined
       console.log(a[8]);//10
       console.log(a[9]);//a*/
    //数组方法
    var a = new Array(1, 2, 3, 4);
    a[8] = 10;
    for (let i = 0; i < a.length; i++) {
        console.log(a[i]);
    }
    //forEach:遍历数组中有值的元素
    //注意:只能遍历有值的元素
    //参数要接收一个函数,用来处理每一次遍历得到的值
  /*  a.forEach(function (e) {
        console.log(e);
    })*/
    //箭头函数简化写法
    a.forEach((e)=>console.log(e))
    //push:添加元素到数组尾部
    a.push(9,8,5);
    console.log(a);
    a.splice(2,2)//(起始,删除个数)
    console.log(a);
</script>
</html>